package com.shuyan.base.algorithm;

import javax.sound.midi.Soundbank;
import javax.swing.*;
import javax.xml.soap.Node;
import java.lang.reflect.Array;
import java.lang.reflect.Field;
import java.security.PublicKey;
import java.text.*;
import java.util.*;

public class OrdinaryExercise {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException {
        String str="a,b,c,,";
        String[] array=str.split(",");
        System.out.println(array.length);
        System.out.println(Arrays.toString(array));
        int a,b;
        a=1;
        b=2;
        String str2="dahai";
        System.out.println(a+b+str2);

        Date dJava=new Date();
        java.sql.Date dSql=new java.sql.Date(555445586);
        System.out.println(getLastDayOfMonth(2020,11)+"jjjjj");
        System.out.println(dSql+"sssss");

        Filter filter=new Filter();
        filter.setField("startTime");
        filter.setValue(new SimpleDateFormat("yyyy-mm-ddd").format(new Date()));
        SearchFormBean searchFormBean=new SearchFormBean();
        List<Filter> filters=new ArrayList<>();
        filters.add(filter);
        searchFormBean.setFilters(filters);
        List<Filter> filters1=searchFormBean.getFilters();
        Filter filter1=new Filter();
        filter1.setField("endTime");
        filter1.setValue(new SimpleDateFormat("yyyy-mm-dd").format(new Date()));
        filters1.add(filter1);
        for (int i=0;i<searchFormBean.getFilters().size();i++){
        System.out.println("*****"+searchFormBean.getFilters().get(i).getField()+"*****");
        }

        int[] arr=new int[6];
        int x=8;
        int y=5;
        float z=5;
            System.out.println("int/int-----"+x/y);
            System.out.println("int/float-----"+x/z);
        System.out.println("int+float"+(x+z));
        String s1="zhonguo";
        String s2="  xiangqi";
        System.out.println(s1+s2);
        System.out.println(x+s1+y);
        System.out.println(getMonthLast(2020,11));
        List list=new ArrayList();
        for (int i=1;i<=50;i++){
        list.add(i);
        Field field=list.getClass().getDeclaredField("elementData");
        field.setAccessible(true);
        Object[] obj=(Object[])field.get(list);
        System.out.print("插入第"+i+"个元素时实际容量为"+obj.length+"  ");
        if(i%5==0) System.out.println();
        }
        Calendar rightNow = Calendar.getInstance();
         NumberFormat numberFormat = new DecimalFormat("0000");

        /** This int is the sequence number ,the default value is 0. */
        int seq = 0;
         final int MAX = 9999;
        StringBuffer sb = new StringBuffer();
         FieldPosition HELPER_POSITION = new FieldPosition(0);
        Format dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
        dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION);
        numberFormat.format(seq, sb, HELPER_POSITION);

        if (seq == MAX) {
            seq = 0;
        } else {
            seq++;
        }
        System.out.println(sb.toString());
    }
    public static String getMonthLast(int year, int month) {
        SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
        Calendar ca = Calendar.getInstance();
        ca.set(Calendar.YEAR, year);
        ca.set(Calendar.MONTH, month);
        ca.add(Calendar.MONTH, -1);
        ca.set(Calendar.DAY_OF_MONTH, ca.getActualMaximum(Calendar.DAY_OF_MONTH));
        String last = sim.format(ca.getTime()) + " 23:59:59";
        return last;
    }
    public static Date getLastDayOfMonth(Integer year, Integer month) {
        Calendar calendar = Calendar.getInstance();
        if (year == null) {
            year = calendar.get(Calendar.YEAR);
        }
        if (month == null) {
            month = calendar.get(Calendar.MONTH);
        }
        calendar.set(year, month, 1);
        calendar.roll(Calendar.DATE, -1);
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");
        String day_last = df.format(calendar.getTime());
        StringBuffer endStr = new StringBuffer().append(day_last).append(" 23:59:59");
        day_last = endStr.toString();
        Date lastDate = null;
        try {
            lastDate = sdf.parse(day_last);

        } catch (java.text.ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return lastDate;
    }
}

